package com.ruoyi.web.controller.report;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version v1.0
 * @ProjectName: report
 * @ClassName: TestApiController
 * @Description: TODO(一句话描述该类的功能)
 * @Author: sunyan
 * @Date: 2022/3/8 15:15
 */
@RestController
@RequestMapping("report/test")
public class TestApiController {

    @PostMapping("api")
    public AjaxResult ApiTest(@RequestBody JSONObject object){
        System.out.println(object);
        List<Map<String,Object>> list = new ArrayList<>();
            Map<String, Object> map1 = new HashMap<>();
            map1.put("name", "张三");
            map1.put("age", 12);
            map1.put("sex", "男");
            map1.put("class", "1班");
            list.add(map1);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("name", "李四");
            map2.put("age", 22);
            map2.put("sex", "男");
            map2.put("class", "4班");
            list.add(map2);
            Map<String, Object> map3 = new HashMap<>();
            map3.put("name", "王五");
            map3.put("age", 8);
            map3.put("sex", "男");
            map3.put("class", "2班");
            list.add(map3);
            Map<String, Object> map4 = new HashMap<>();
            map4.put("name", "刘能");
            map4.put("age", 57);
            map4.put("sex", "男");
            map4.put("class", "3班");
            list.add(map4);
            Map<String, Object> map5 = new HashMap<>();
            map5.put("name", "广坤");
            map5.put("age", 55);
            map5.put("sex", "男");
            map5.put("class", "5班");
            list.add(map5);
        return AjaxResult.success(list);
    }
    @GetMapping("api")
    public AjaxResult ApiSetTest(){
        JSONObject map = new JSONObject();
        map.put("name", "张三封");
        map.put("age", "12");
        map.put("sex", "男");
        map.put("class", "1班");
        return AjaxResult.success(map);
    }
    @GetMapping("api/set")
    public JSONObject ApiPageTest(@RequestParam(name = "pageSize",defaultValue = "100") Integer pageSize,
                                  @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum,
                                  @RequestParam(name = "name")String name){
        System.out.println(pageSize);
        System.out.println(pageNum);
        List<Map<String,Object>> list = new ArrayList<>();
        for(int i = 0; i < pageSize/5 ;i++){
            Map<String, Object> map1 = new HashMap<>();
            map1.put("name", name);
            map1.put("age", 12);
            map1.put("sex", "男");
            map1.put("class",String.valueOf(i)+"班");
            list.add(map1);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("name", "李四");
            map2.put("age", 22);
            map2.put("sex", "男");
            map2.put("class", String.valueOf(i)+"班");
            list.add(map2);
            Map<String, Object> map3 = new HashMap<>();
            map3.put("name", "王五");
            map3.put("age", 8);
            map3.put("sex", "男");
            map3.put("class", String.valueOf(i)+"班");
            list.add(map3);
            Map<String, Object> map4 = new HashMap<>();
            map4.put("name", "刘能");
            map4.put("age", 57);
            map4.put("sex", "男");
            map4.put("class", String.valueOf(i)+"班");
            list.add(map4);
            Map<String, Object> map5 = new HashMap<>();
            map5.put("name", "广坤");
            map5.put("age", 55);
            map5.put("sex", "男");
            map5.put("class", String.valueOf(i)+"班");
            list.add(map5);
        }
        JSONObject object = new JSONObject();
        object.put("data",list);
        object.put("count",100);
        return object;
    }
    @GetMapping("api/dict")
    public JSONObject dictTest(){
        List<Map<String,Object>> list = new ArrayList<>();
        for(int i = 0; i < 5 ;i++){
            Map<String, Object> map1 = new HashMap<>();
            map1.put("name", "法外狂徒");
            map1.put("age", 12);
            map1.put("sex", "0");
            map1.put("class",String.valueOf(i)+"班");
            list.add(map1);
            Map<String, Object> map2 = new HashMap<>();
            map2.put("name", "李四");
            map2.put("age", 22);
            map2.put("sex", "0");
            map2.put("class", String.valueOf(i)+"班");
            list.add(map2);
            Map<String, Object> map3 = new HashMap<>();
            map3.put("name", "王五");
            map3.put("age", 8);
            map3.put("sex", "1");
            map3.put("class", String.valueOf(i)+"班");
            list.add(map3);
            Map<String, Object> map4 = new HashMap<>();
            map4.put("name", "刘能");
            map4.put("age", 57);
            map4.put("sex", "1");
            map4.put("class", String.valueOf(i)+"班");
            list.add(map4);
            Map<String, Object> map5 = new HashMap<>();
            map5.put("name", "广坤");
            map5.put("age", 55);
            map5.put("sex", "0");
            map5.put("class", String.valueOf(i)+"班");
            list.add(map5);
        }
        JSONObject object = new JSONObject();
        object.put("data",list);
        return object;
    }
}
